package com.xiaoke.java;

/**
 * -XX:+PrintGCDetails
 * @author yd
 * @version 1.0
 * @date 2022/3/3 22:27
 */
public class RefCountGC {

    //这个成员的唯一的作用就是占用一点内存
    private byte[] bigSize = new byte[5 * 1024 * 1024];

    Object reference = null;


    public static void main(String[] args) {
        RefCountGC obj1 = new RefCountGC();
        RefCountGC obj2 = new RefCountGC();

        obj1.reference = obj2;
        obj2.reference = obj1;

        obj1 = null;
        obj2 = null;

        //显式的执行垃圾回收行为
        //这里发生GC、obj1、obj2能否被回收？
        System.gc();


        try {
            Thread.sleep(100000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }

}
